package com.hst.capacity.facade.rest;

import cn.hutool.core.util.StrUtil;
import com.hst.capacity.application.biz.ExpressOrderBiz;
import com.hst.capacity.application.biz.IntercityOrderBiz;
import com.hst.capacity.application.biz.OrderBiz;
import com.hst.capacity.application.biz.OrderPoolBiz;
import com.hst.capacity.domain.model.request.OrderForDispatchParam;
import com.hst.capacity.domain.model.request.dispatcher.DispatcherOrderParam;
import com.hst.capacity.domain.model.request.dispatcher.DispatcherSearchOrderParam;
import com.hst.capacity.domain.model.request.specialcar.SpListParam;
import com.hst.capacity.domain.model.response.DefaultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

import static com.hst.capacity.domain.model.response.DefaultVO.success;

@RequestMapping("/dispatcher")
@RestController
public class DispatcherController {

    @Autowired
    OrderBiz orderBiz;

    @Autowired
    OrderPoolBiz orderPoolBiz;

    @Autowired
    ExpressOrderBiz exOrderBiz;

    @Autowired
    IntercityOrderBiz icOrderBiz;

    /**
     * 全部未派单订单
     * @param param
     * @return
     */
    @PostMapping("/pending/order/list")
    private DefaultVO dispatherPendingOrderList(@RequestBody @Valid DispatcherOrderParam param){
        DefaultVO vo = success(orderBiz.dispatherPendingOrderList(param));
        return vo;
    }

    /**
     * 专车订单检索查询
     * @param param
     * @return
     */
    @PostMapping("/order-pool/search")
    private DefaultVO orderPoolSearch(@RequestBody @Valid DispatcherSearchOrderParam param){
        boolean historyFlg = false;
        if (StrUtil.isEmpty(param.getHistoryKbn()))
            historyFlg = true;
        return success(orderPoolBiz.dispatherOrderPoolSearch(param, historyFlg));
    }

    /**
     * 城际订单检索查询
     * @param param
     * @return
     */
    @PostMapping("/intercity/order/search")
    private DefaultVO intercityOrderSearch(@RequestBody @Valid DispatcherSearchOrderParam param){
        boolean historyFlg = false;
        if (StrUtil.isEmpty(param.getHistoryKbn()))
            historyFlg = true;
        return success(icOrderBiz.dispatherIcOrderSearch(param, historyFlg));
    }

    /**
     * 快车订单检索查询
     * @param param
     * @return
     */
    @PostMapping("/express/order/search")
    private DefaultVO expressOrderSearch(@RequestBody @Valid DispatcherSearchOrderParam param){
        boolean historyFlg = true;
        if (StrUtil.isEmpty(param.getHistoryKbn()))
            historyFlg = false;
        return success(exOrderBiz.dispatherExOrderSearch(param,historyFlg));
    }

//    /**
//     * 全部发票信息
//     * @param param
//     * @return
//     */
//    @PostMapping("/invoice/list")
//    private DefaultVO dispatherInvoiceList(@RequestBody @Valid DispatcherInvoiceParam param){
//        DefaultVO vo = success(orderBiz.dispatherPendingOrderList(param));
//        return vo;
//    }

}
